<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Test extends CI_Controller {

	public function test_cli()
	{
		echo "Hello world!".PHP_EOL;
	}

	//PHP FTP test
	$ftp_conn = @ftp_connect("ftp.isu.edu.tw", "21", 5);
	echo "ftp_conn:".$ftp_conn."\n";

	//PHP SMTP test
	$smtp_conn = @smtp_connect("smtp.gmail.com",$smtp_port="465",$smtp_timeout="5");
	echo "smtp_conn:".$smtp_conn."\n";

	//PHP POP test
	$pop_conn = @pop_connect("pop.gmail.com",$pop_port="995",$pop_timeout="5");
	echo "pop_conn:".$pop_conn."\n";

	//PHP MySQL test
	$address = gethostbyname('movie.siagoo.com');
	$service_port = 3306;

	$fp = @fsockopen( $address , $service_port, $errno , $errstr, 2 );
	if (!$fp) {
			echo $errno."\n";
	} else {
			echo "connect ".$address."(".$service_port.") ok\n";
	}


	//functions
	function smtp_connect($smtp_host,$smtp_port="25",$smtp_timeout="5",$smtp_crypto=NULL)
	{
		$ssl = NULL;
		if ($smtp_crypto == 'ssl') $ssl = 'ssl://';
		$smtp_connect = @fsockopen($ssl.$smtp_host,
										$smtp_port,
										$errno,
										$errstr,
										$smtp_timeout);

		if ( ! @is_resource($smtp_connect))
		{
			//return "smtp_error:".$errno." ".$errstr;
			return false;
		}
		else
		{
			return $smtp_connect;
		}
	}

	function pop_connect($pop_host,$pop_port="110",$pop_timeout="5",$pop_crypto=NULL)
	{
		$ssl = NULL;
		if ($pop_crypto == 'ssl') $ssl = 'ssl://';
		$pop_connect = @fsockopen($ssl.$pop_host,
										$pop_port,
										$errno,
										$errstr,
										$pop_timeout);

		if ( ! @is_resource($pop_connect))
		{
			//return "pop_error:".$errno." ".$errstr;
			return false;
		}
		else
		{
			return $pop_connect;
		}
	}
}

/* End of file test.php */
/* Location: ./application/controllers/test.php */